#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int N, V, v[maxn], w[maxn];
int dp[maxn];
int main() {
  cin >> N >> V;
  for (int i = 1; i <= N; ++i) cin >> v[i] >> w[i];

  for (int i = 1; i <= N; ++i) {
    for (int j = V; j >= v[i]; --j) {
      dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
    }
  }

  cout << dp[V] << endl;
}
